<template>
    <el-container>
        <el-header>
            <div>
                <img src="../assets/img.png" alt class="logo_img" />
                <span>停车场管理平台</span>
            </div>
            <el-button type="info" @click="logout" active-text-color="#ffd04b">安全退出</el-button>
        </el-header>
        <el-container class="menu_con">
            <el-aside >

                <el-menu background-color="#545c64" text-color="#fff" active-text-color="#ffd04b" :router="true" :default-active="activePath">
                    <el-submenu :index="it.path"  v-for="it in menuList" :key="it.id">
                        <template slot="title">
                            <i class="el-icon-location"></i>
                            <span>{{it.title}}</span>
                        </template>
                        <el-menu-item-group>

                            <el-menu-item :index="item.path" v-for="item in it.slist" :key="item.id" @click="savePath">
                                <span> {{item.title}}</span>
                            </el-menu-item>

                        </el-menu-item-group>

                            </el-submenu>

                        </el-menu>

            </el-aside>
            <el-main>
                <router-view></router-view>
                <!--                {{menuList}}}-->
            </el-main>
        </el-container>
    </el-container>
</template>
<script>
export default {
  data () {
    return {
      // 左侧菜单
      menuList: [],
      iconsObject: {
        '100': 'iconfont iconguanliyuan',
        '200': 'iconfont iconsport',
        '101': 'iconfont icondenglu',
        '102': 'iconfont iconmima',
        '103': 'iconfont iconsport',
        '104': 'iconfont iconshangpin',
        '201': 'iconfont iconshu',
        '202': 'iconfont iconkaluli',
        '203': 'iconfont iconshiwu',
        '204': 'iconfont icondenglu'
      },

      // 被激活的连接
     activePath: '/user'
    }
  },
  created () {
    this.getMenuList()
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    logout () {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    async getMenuList () {
      const {data: res} = await this.$http.get('menus')
      console.log(res.data)
      // eslint-disable-next-line eqeqeq
      if (res.status != 200) return this.$message.error('操作失败！！！')
      this.menuList = res.data
    },
    savePath (activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    }
  }}
</script>
<style lang="less" scoped>
  .el-header {
    background-color: #373d41;
    display: flex;
    justify-content: space-between;// 左右贴边
    padding-left: 0%;// 左边界
    align-items: center;// 水平
    color: #fff;
    font-size: 20px;
    > div { //左侧div加布局
      display: flex;
      align-items: center;
      span {
        margin-left: 15px;
      }
    }
  }
  .el-aside {
    background-color: #333744;
    .el-menu{
      border-right: none;// 对其右边框
    }
  }
  .el-main {
    background-color: #eaedf1;
  }
  .home-container {
    height: 100%;
  }
  .logo_img {
    width: 20%;
    height: 100%;
  }
  .iconfont{
    margin-right: 10px;
  }
  .toggle-button{
    background-color:#4A5064;
    font-size: 10px;
    line-height: 24px;
    color:#fff;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;// 显示鼠标指针为：小手
  }
</style>
